package com.yanftch.hdc_tools.action

import com.intellij.ide.actions.QuickSwitchSchemeAction
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project

class ToolsListAction : QuickSwitchSchemeAction(), DumbAware {
    override fun fillActions(project: Project?, group: DefaultActionGroup, dataContext: DataContext) {
        if (project == null) {
            return
        }
//        addAction("com.yanftch.hdc_tools.action.InstallAction", group)
        addAction("com.yanftch.hdc_tools.action.UnInstallAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.UnInstallWithHSPAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.KillAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.StartAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.RestartAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.CleanDataAction", group) // 代码写完了，没法自测...
        addAction("com.yanftch.hdc_tools.action.CleanDataAndRestartAction", group) // 代码写完了，没法自测...
        group.addSeparator()
        addAction("com.yanftch.hdc_tools.action.StartAppWithDebuggerAction", group) // ✅
        addAction("com.yanftch.hdc_tools.action.ReStartAppWithDebuggerAction", group) // ✅
        group.addSeparator()
        addAction("com.yanftch.hdc_tools.action.CopyToPasteAction", group) // ✅

    }

    private fun addAction(actionId: String, toGroup: DefaultActionGroup) {
        // add action to group if it is available
        ActionManager.getInstance().getAction(actionId)?.let {
            toGroup.add(it)
        }
    }

    override fun isEnabled() = true
    override fun getPopupTitle(e: AnActionEvent) = "HDC Commands Popup"
}